﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;


namespace AppCommerciauxWinForm
{
    public partial class FormPrincipal : Form
    {
        public FormPrincipal()
        {
            InitializeComponent();

            ConnectBaseSqlite();
            if (connexionSqlite)
            {
                //charger la list client
                InitClientTest();
                //charger la list RDV

                //charger la list Commande



            }
            
        }

        public string connectionString;
        public bool connexionSqlite = false;
        private void ConnectBaseSqlite()
        {
            connectionString = @" Data source = C:\livrable3\liv3";
            using(SQLiteConnection con = new SQLiteConnection(connectionString))
            {
                try
                {
                    con.Open();
                    if (con.State == ConnectionState.Open)
                    { 
                        connexionSqlite = true;
                        MessageBox.Show("connection sqlite ok");  
                    }
                }
                catch (Exception ex)
                {
                    connexionSqlite = false;
                    MessageBox.Show(ex.Message);
                }
            }
        }


        private void InitClientTest()
        {

            List<EntityTest.ClientTest> ListClientTest = new List<EntityTest.ClientTest>();

            ListClientTest.Add(new EntityTest.ClientTest("nom1", "prenom1"));
            ListClientTest.Add(new EntityTest.ClientTest("nom2", "prenom2"));

            this.listViewClient.Items.Clear();

            foreach (EntityTest.ClientTest p in ListClientTest)
            {
                string[] arr = new string[3];
                ListViewItem itm;
                //add items to ListView
                arr[0] = p.Nom;
                arr[1] = p.Prenom;
                arr[2] = "";

                itm = new ListViewItem(arr);
                itm.Tag = p.Nom;
                listViewClient.Items.Add(itm);
            }
            this.listViewClient.ListViewItemSorter = new ListViewItemComparer(columnHeaderNom.Index);
        }
    }
}
